package com.tiger.cloud.controller.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tiger.cloud.common.mybatis.BaseController;
import com.tiger.cloud.filter.CurrentUserId;
import com.tiger.cloud.filter.IgnoreAuth;
import com.tiger.cloud.model.system.SysDict;
import com.tiger.cloud.service.system.ISysDictService;
import com.tiger.cloud.util.Page;
import com.tiger.cloud.util.Response;
import com.tiger.cloud.util.ResponseUtil;

import io.swagger.annotations.Api;

@Controller
@RequestMapping(value = "dict")
@Api(hidden=true)
public class SysDictController extends BaseController {

	private static final Logger logger=Logger.getLogger(SysDictController.class);
	
	@Autowired
	private ISysDictService sysDictService;
	
	@IgnoreAuth
	@RequestMapping(method = RequestMethod.GET)
	public String index(HttpServletRequest request) {
		return "/system/dict/dict-list";
	}
	
	@IgnoreAuth
	@RequestMapping(value = "updateGet", method = RequestMethod.GET)
	public String update(HttpServletRequest request,String id) {
		request.setAttribute("sysDict", sysDictService.get(id));
		return "/system/dict/dict-update";
	}
	
	@IgnoreAuth
	@RequestMapping(value = "insertGet", method = RequestMethod.GET)
	public String insertGet(HttpServletRequest request) {
		return "/system/dict/dict-insert";
	}
	
	@IgnoreAuth
	@RequestMapping(value = "info", method = RequestMethod.GET)
	public String info(HttpServletRequest request,String id) {
		request.setAttribute("sysDict", sysDictService.get(id));
		return "/system/dict/dict-info";
	}
	
	@IgnoreAuth
	@RequestMapping(value = "find", method = RequestMethod.POST)
	@ResponseBody
	public Response find(@CurrentUserId Long userId,HttpServletRequest request){
		Map<String, Object> params=getPageMap(request);
		Page<SysDict> datas=sysDictService.page(params);
		return ResponseUtil.ok(datas);
	}
	
	@IgnoreAuth
	@RequestMapping(value = "list", method = RequestMethod.POST)
	@ResponseBody
	public Response list(HttpServletRequest request){
		Map<String, Object> params=getPageMap(request);
		return ResponseUtil.ok(sysDictService.find(params));
	}
	
	@IgnoreAuth
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public Response update(HttpServletRequest request,SysDict sysDict){
		sysDictService.update(sysDict);
		return ResponseUtil.ok();
	}
	
	@IgnoreAuth
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	public Response add(HttpServletRequest request,SysDict sysDict){
		sysDict.setStatus("1");
		sysDictService.insert(sysDict);
		return ResponseUtil.ok();
	}

	@IgnoreAuth
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public Response delete(@CurrentUserId Long userId,HttpServletRequest request){
		HashMap<String, Object> param=getParamMap(request);
		sysDictService.remove(param);
		return ResponseUtil.ok();
	}

}